//
//  PS_SquareNewViewController.m
//  FinanceSupermarket
//
//  Created by 丹丹 on 2018/12/17.
//  Copyright © 2018年 xuezi. All rights reserved.
//

#import "PS_SquareNewViewController.h"
#import "FSSegmentTitleView.h"
#import "FSPageContentView.h"
#import "PS_TuiJianViewController.h"
#import "PS_ReMenViewController.h"
#import "PS_HuiDaViewController.h"
#import "PS_WeiQuanViewController.h"
#import "BHInfiniteScrollView.h"
#import "PS_AskViewController.h"
@interface PS_SquareNewViewController ()<FSSegmentTitleViewDelegate,FSPageContentViewDelegate,BHInfiniteScrollViewDelegate,UIScrollViewDelegate>
{
    UIView * scrollLine;
}
@property (nonatomic, strong) FSSegmentTitleView *titleView;
@property (nonatomic, strong) FSPageContentView *pageContentView;
@property (nonatomic, strong) UIView * headerView;
@property (nonatomic, strong) BHInfiniteScrollView *infinitePageView;
@property (nonatomic, strong) UIScrollView * backScroll;

@end

@implementation PS_SquareNewViewController

- (UIScrollView *)backScroll
{
    if (_backScroll == nil) {
        
        _backScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT - SafeAreaBottomHeight - 49)];
        _backScroll.showsVerticalScrollIndicator = NO;
        _backScroll.delegate = self;
        _backScroll.backgroundColor =RGBCOLOR(238, 238, 238);
        _backScroll.scrollEnabled = NO;
    }
    
    return _backScroll;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.nav_titleLabel.text = @"广场";
    self.nav_btmView.hidden = YES;
    self.nav_backImg.hidden = YES;
    self.nav_backButton.hidden = YES;
//    self.view.backgroundColor = RGBCOLOR(238, 238, 238);
    [self.view addSubview:self.backScroll];
    self.backScroll.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT + 175);
    [self.backScroll addSubview:self.headerView];
    
    NSArray *titles  = @[@"推荐",@"热门",@"回答",@"维权"];
    
    self.titleView = [[FSSegmentTitleView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight+175, SCREEN_WIDTH, 50) titles:titles delegate:self indicatorType:FSIndicatorTypeNone];
    self.titleView.backgroundColor = [UIColor whiteColor];
    [self.backScroll addSubview:_titleView];
    
    scrollLine = [[UIView alloc]initWithFrame:CGRectMake(15,SafeAreaTopHeight+50+175,(SCREEN_WIDTH-120)/4, 2)];
    scrollLine.backgroundColor = [UIColor colorWithHexString:@"f7bdcb"];
    [self.backScroll addSubview:scrollLine];
    
    
    NSMutableArray *childVCs = [[NSMutableArray alloc]init];
    PS_TuiJianViewController * allVC = [[PS_TuiJianViewController alloc]init];
    
    PS_ReMenViewController * dshVC = [[PS_ReMenViewController alloc]init];
    
    PS_HuiDaViewController * shtgVC = [[PS_HuiDaViewController alloc]init];
    
    PS_WeiQuanViewController * shsbVC =[[PS_WeiQuanViewController alloc]init];
    
    [childVCs addObject:allVC];
    [childVCs addObject:dshVC];
    [childVCs addObject:shtgVC];
    [childVCs addObject:shsbVC];
    
    
    self.pageContentView = [[FSPageContentView alloc]initWithFrame:CGRectMake(0,SafeAreaTopHeight+52+175, CGRectGetWidth(self.view.bounds),SCREEN_HEIGHT - 175-52-SafeAreaTopHeight-SafeAreaBottomHeight-49) childVCs:childVCs parentVC:self delegate:self];
    [self.backScroll addSubview:_pageContentView];
    
    
    [self loadTiWen];
    // Do any additional setup after loading the view.
}

- (void)loadTiWen{
    
    UIButton * askButton = [UIButton buttonWithType:UIButtonTypeCustom];
    askButton.frame = CGRectMake(SCREEN_WIDTH - 80-25, SCREEN_HEIGHT - 80-49-30,80,80);
    [askButton setBackgroundImage:[UIImage imageNamed:@"xuancengtiwen"] forState:UIControlStateNormal];
    [askButton addTarget:self action:@selector(askAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:askButton];
}
- (void)askAction:(UIButton *)sender{
    
    PS_AskViewController * VC = [[PS_AskViewController alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}
- (UIView *)headerView{
    
    if (_headerView ==nil) {
        
        _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 175+SafeAreaTopHeight)];
        BHInfiniteScrollView *infinitePageView1 = [BHInfiniteScrollView infiniteScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,175+SafeAreaTopHeight) Delegate:self ImagesArray:@[] PlageHolderImage:[UIImage imageNamed:@"arror1"]];
        infinitePageView1.backgroundColor = [UIColor yellowColor];
        infinitePageView1.dotSize = 5;
        infinitePageView1.pageControlAlignmentOffset = CGSizeMake(0, 20);
        infinitePageView1.titleView.textColor = [UIColor whiteColor];
        infinitePageView1.titleView.margin = 30;
        infinitePageView1.titleView.hidden = YES;
        infinitePageView1.scrollTimeInterval = 4.5f;
        infinitePageView1.autoScrollToNextPage = YES;
        infinitePageView1.delegate = self;
        [infinitePageView1 setContentMode:UIViewContentModeScaleToFill];
        [_headerView addSubview:infinitePageView1];//头部广告栏
        _infinitePageView = infinitePageView1;
        
        
    }
    
    return _headerView;
}
#pragma mark --
- (void)FSSegmentTitleView:(FSSegmentTitleView *)titleView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex
{
    self.pageContentView.contentViewCurrentIndex = endIndex;
    scrollLine.frame = CGRectMake(SCREEN_WIDTH/4*endIndex+15,SafeAreaTopHeight+50+175,(SCREEN_WIDTH-120)/4, 2);
}

- (void)FSContenViewDidEndDecelerating:(FSPageContentView *)contentView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex
{
    self.titleView.selectIndex = endIndex;
    
    scrollLine.frame = CGRectMake(SCREEN_WIDTH/4*endIndex+15,SafeAreaTopHeight+50+175,(SCREEN_WIDTH-120)/4, 2);
}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    
//    NSLog(@"scrollView.contentOffset.y = %f",scrollView.contentOffset.y);
//    if (scrollView.contentOffset.y >240 ) { //外滑动内不滑动
//        
//        self.backScroll.scrollEnabled = NO;
//        [[NSNotificationCenter defaultCenter]postNotificationName:@"TABLEHUDONG" object:nil];
//       
//    }else{
//        self.backScroll.scrollEnabled = YES;
//        [[NSNotificationCenter defaultCenter]postNotificationName:@"JINZHITABLEHUDONG" object:nil];
//    }
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
